//
//  YJBannerListCell.m
//  SnackCourier
//
//  Created by qianfeng01 on 15/7/20.
//  Copyright (c) 2015年 qianfeng01. All rights reserved.
//

#import "YJBannerListCell.h"
#import "YJBannerListModel.h"
#import "UIButton+WebCache.h"

@implementation YJBannerListCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)showDataWithArray:(NSMutableArray *)array myblock:(YJBannerListBlock)myblock{
    self.myblock =myblock;
    self.array =array;
    self.scrollView.contentSize =CGSizeMake(self.frame.size.width*array.count, self.frame.size.height);
    
    self.scrollView.pagingEnabled =YES;
    self.scrollView.bounces=NO;
    self.scrollView.alwaysBounceVertical =NO;
    int i=0;
    for (YJBannerListModel *mode in array) {
        UIButton *button =[UIButton buttonWithType:(UIButtonTypeSystem)];
        button.frame =CGRectMake(self.frame.size.width*i, 0, self.frame.size.width, self.frame.size.height);
        [button sd_setBackgroundImageWithURL:[NSURL URLWithString:mode.picUrl] forState:(UIControlStateNormal)];
        button.tag =101+i;
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.scrollView addSubview:button];
        i++;
    }
    
    
    
}

-(void)buttonClick:(UIButton *)button{
    if (self.myblock) {
        YJBannerListModel *model =self.array[button.tag-101];
        self.myblock(model.linkUrl);
    }
}
@end
